package com.yanxin.credit.configuration;

import com.yanxin.credit.properties.MinIoProperties;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class MinioConfiguration {

    @Autowired
    private MinIoProperties minIoProperties;

    @Bean
    public MinioClient minioClient() {
        try {
            return new MinioClient(minIoProperties.getEndPoint(),
                    minIoProperties.getAccessKey(), minIoProperties.getSecretKey());
        } catch (InvalidEndpointException | InvalidPortException e) {
            throw new IllegalStateException("Minio Client init Fail");
        }
    }
}
